﻿using JsonConversion;
using JsonRequest;
using Newtonsoft.Json;
using RTracker.Models.Common;
using RTracker.Models.ErrorLog;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;


namespace RTracker.Models.Organization
{
    public class MOrganization
    {

        /// static variable RowSize from config settings to get list of this row size.
        public static int nRowSize = Convert.ToInt32(ConfigurationManager.AppSettings["TotalRecordsInListUser"]);

        /// <summary>
        ///  This function is used to get complete organization list
        /// </summary>
        /// <returns>List of type COrganization</returns>
        public GOrganization GetOrganizationGridList(COrganization objCOrganization, CAuthenticationContext objCAuthenticationContext)
        {
            GOrganization objGOrganization = new GOrganization();
            int nTotalRecords = 0;
            int nCurrentRowSize = nRowSize;

            if (objCOrganization.RowSize != 0)
            {
                nCurrentRowSize = objCOrganization.RowSize;
            }
            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("r_get_organization_paging_list_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@organization_id", SqlDbType.Int).Value = objCOrganization.OrganizationId;
                    cmd.Parameters.Add("@page_number", SqlDbType.Int).Value = objCOrganization.PageNumber;
                    cmd.Parameters.Add("@row_size", SqlDbType.Int).Value = nCurrentRowSize;
                    cmd.Parameters.Add("@sort_on", SqlDbType.VarChar).Value = objCOrganization.SortOn;
                    cmd.Parameters.Add("@sort_type", SqlDbType.VarChar).Value = objCOrganization.SortType;
                    cmd.Parameters.Add("@search", SqlDbType.VarChar).Value = objCOrganization.Search;
                    cmd.Parameters.Add("@searchon", SqlDbType.VarChar).Value = objCOrganization.SearchOn;
                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);

                    DataTable dt = new DataTable();

                    int rowsAffected = adp.Fill(dt);

                    objGOrganization.Paging = new CPaging();
                    if (rowsAffected > 0)
                    {
                        objGOrganization.LstCOrganization = dt.ConvertToListFromDataTableOrg();
                        objGOrganization.LstCOrganization[0].PageNumber = int.Parse(cmd.Parameters["@idOut"].Value.ToString());
                        objGOrganization.Paging.PageNumber = objGOrganization.LstCOrganization[0].PageNumber;
                    }
                    else
                    {
                        objGOrganization.LstCOrganization = null;
                    }

                    
                    nTotalRecords = int.Parse(cmd.Parameters["@error"].Value.ToString());

                    objGOrganization.Status = new CStatus();

                    if (nTotalRecords < 0)
                    {
                        objGOrganization.Status.Success = false;
                        objGOrganization.Status.StatusDetails = nTotalRecords.DbError();
                    }
                    else
                    {
                        objGOrganization.Paging.TotalRecordsCount = nTotalRecords;
                        objGOrganization.Paging.PageSize = nCurrentRowSize;

                        objGOrganization.Status.Success = true;
                        objGOrganization.Status.StatusDetails = "success";
                    }

                }
                catch (Exception ex)
                {
                    objGOrganization.Status.Success = false;
                    objGOrganization.Status.StatusDetails = ex.Message;
                }
            }
            return objGOrganization;
        }

        /// <summary>
        ///  This function is used to get complete organization list
        /// </summary>
        /// <returns>List of type COrganization</returns>
        public CStatus GetOrganizationList(CAuthenticationContext objCAuthenticationContext, out List<COrganization> lstCOrganization)
        {
            CStatus oCStatus = new CStatus();
            lstCOrganization = new List<COrganization>();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_get_organization_list_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        //cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        //cmd.Parameters["@error"].Direction = ParameterDirection.Output;
                        SqlDataAdapter adp = new SqlDataAdapter(cmd);

                        DataTable dt = new DataTable();

                        int rowsAffected = adp.Fill(dt);

                        if (rowsAffected > 0)
                        {
                            lstCOrganization.AddRange(dt.ConvertToListFromDataTableOrg());
                        }

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }

        /// <summary>
        /// Function to get details for an Organization.
        /// </summary>
        /// <param name="oCOrganization">object of type COrganization contains Organization id to get details for that Organization</param>
        /// <returns>object of type CStatus contains status and details</returns>
        public CStatus GetOrganizationDetail(CAuthenticationContext objCAuthenticationContext, ref COrganization oCOrganization)
        {
            CStatus oCStatus = new CStatus();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("r_get_organization_detail_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@organization_id", SqlDbType.Int).Value = oCOrganization.OrganizationId;
                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;

                        SqlDataAdapter adp = new SqlDataAdapter(cmd);

                        DataTable dt = new DataTable();

                        int rowsAffected = adp.Fill(dt);

                        if (rowsAffected > 0)
                        {
                            oCOrganization = dt.ConvertToListFromDataTableOrg()[0];
                        }

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.DetailSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }

        /// <summary>
        ///This method is used to save a Organization.
        /// </summary>
        /// <param name="oCAuthenticationContext">Object of type CAuthenticationContext</param>
        /// <param name="oOrganization">Object of type COrganization</param>
        /// <returns>Object of type CStatus</returns>
        public CStatus UpdateOrganization(CAuthenticationContext objCAuthenticationContext, ref COrganization oCOrganization)
        {
            CStatus oCStatus = new CStatus();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_update_organization_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@organization_id", SqlDbType.Int).Value = oCOrganization.OrganizationId;
                        //,@organization_name nvarchar(50)
                        cmd.Parameters.Add("@organization_name", SqlDbType.NVarChar).Value = oCOrganization.OrganizationName;
                        //,@address nvarchar(255)
                        cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = oCOrganization.Address;
                        //,@city nvarchar(50)
                        cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = oCOrganization.City;
                        //,@state nvarchar(50)
                        cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = oCOrganization.State;
                        //,@zip nvarchar(15)
                        cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = oCOrganization.Zip;
                        //,@web_site nvarchar(255)
                        cmd.Parameters.Add("@web_site", SqlDbType.NVarChar).Value = oCOrganization.WebSite;
                        //,@primary_email nvarchar(255)
                        cmd.Parameters.Add("@primary_email", SqlDbType.NVarChar).Value = oCOrganization.PrimaryEmail;
                        //,@secondary_email nvarchar(255)
                        cmd.Parameters.Add("@secondary_email", SqlDbType.NVarChar).Value = oCOrganization.SecondaryEmail;
                        //,@phone_number nvarchar(50)
                        cmd.Parameters.Add("@phone_number", SqlDbType.NVarChar).Value = oCOrganization.PhoneNumber;

                        cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }

        public CStatus CreateOrganization(CAuthenticationContext oAuthenticationContext, ref COrganization oCOrganization)
        {
            CStatus oCStatus = new CStatus();

            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_create_organization_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        //@organization_name nvarchar(50)
                        cmd.Parameters.Add("@organization_name", SqlDbType.NVarChar).Value = oCOrganization.OrganizationName;
                        //,@address nvarchar(255)
                        cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = oCOrganization.Address;
                        //,@city nvarchar(50)
                        cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = oCOrganization.City;
                        //,@state nvarchar(50)
                        cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = oCOrganization.State;
                        //,@zip nvarchar(15)
                        cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = oCOrganization.Zip;
                        //,@web_site nvarchar(255)
                        cmd.Parameters.Add("@web_site", SqlDbType.NVarChar).Value = oCOrganization.WebSite;
                        //,@primary_email nvarchar(255)
                        cmd.Parameters.Add("@primary_email", SqlDbType.NVarChar).Value = oCOrganization.PrimaryEmail;
                        //,@secondary_email nvarchar(255)
                        cmd.Parameters.Add("@secondary_email", SqlDbType.NVarChar).Value = oCOrganization.SecondaryEmail;
                        //,@phone_number nvarchar(50)
                        cmd.Parameters.Add("@phone_number", SqlDbType.NVarChar).Value = oCOrganization.PhoneNumber;
                        //--,@logo nvarchar(255)
                        //cmd.Parameters.Add("@logo", SqlDbType.NVarChar).Value = oCOrganization.Logo;

                        cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = oAuthenticationContext.UserId;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }

        /// <summary>
        /// This function is used to delete organization 
        /// </summary>
        /// <param name="Ids">object of type COrganization</param>
        /// <returns>object of type CStatus</returns>
        public CStatus DeleteOrganization(COrganization oCOrganization, CAuthenticationContext objCAuthenticationContext)
        {
            CStatus oCStatus = new CStatus();
            JsonObject oJson = new JsonObject();
            JsonRequest.Request oRequest = new JsonRequest.Request();
            try
            {

                // Pass the parameters to the json object required for requesting ajax layer function.
                oJson.oList.Add("oCOrganization", oCOrganization);
                oJson.oList.Add("oAuthenticationContext", objCAuthenticationContext);
                // Call GetJsonstring to convert the object in json string format
                string json = oJson.GetJsonString();
                // Clear the list object for other request.
                oJson.oList.Clear();
                string URL = "";
                // Form url of service end point.
                URL = ConfigurationManager.AppSettings["WcfBaseUrl"] + "/Organization/DeleteOrganization";

                // Request Restful Ajax layer function by passing json object.
                object Result = oRequest.Execute(URL, json, "POST");

                dynamic dynobj = JsonConvert.DeserializeObject(Result.ToString());
                oCStatus = dynobj["DeleteOrganizationResult"].ToObject<CStatus>();
            }
            // In case exception occurs then status becomes false
            catch (Exception ex)
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = ex.Message;
            }
            return oCStatus;
        }

        #region Lock Code
        /// <summary>
        /// Sets the softlock on the record whose Id is passed.
        /// </summary>
        /// <param name="GroupId">Id of the record from which you want to set softlock</param>
        /// <returns>Object of type CStatus</returns>
        public CStatus SetOrganizationSoftLock(COrganization oCOrganization, CAuthenticationContext objCAuthenticationContext)
        {
            CStatus oCStatus = new CStatus();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_set_organization_soft_lock_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@organization_id", SqlDbType.NVarChar).Value = oCOrganization.OrganizationId;
                        cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = oCOrganization.CreatedBy;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }


        /// <summary>
        /// Sets the hardlock on the record whose Id is passed.
        /// </summary>
        /// <param name="GroupId">object of type COrganization</param>
        /// <returns>Object of type CStatus</returns>
        public CStatus SetOrganizationHardLock(COrganization oCOrganization, CAuthenticationContext objCAuthenticationContext)
        {
            CStatus oCStatus = new CStatus();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_set_organization_hard_lock_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@organization_id", SqlDbType.NVarChar).Value = oCOrganization.OrganizationId;
                        cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = oCOrganization.CreatedBy;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }


        /// <summary>
        /// Releases the softlock on the record whose Id is passed.
        /// </summary>
        /// <param name="GroupId">object of type COrganization</param>
        /// <returns>Object of type CStatus</returns>
        public CStatus ReleaseOrganizationSoftLock(COrganization oCOrganization, CAuthenticationContext objCAuthenticationContext)
        {

            CStatus oCStatus = new CStatus();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_release_organization_soft_lock_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@organization_id", SqlDbType.NVarChar).Value = oCOrganization.OrganizationId;
                        cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = oCOrganization.CreatedBy;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }

        /// <summary>
        /// Releases the hardlock on the record whose Id is passed.
        /// </summary>
        /// <param name="GroupId">object of type COrganization</param>
        /// <returns>Object of type CStatus</returns>
        public CStatus ReleaseOrganizationHardLock(COrganization oCOrganization, CAuthenticationContext objCAuthenticationContext)
        {
            CStatus oCStatus = new CStatus();
            if (!CCommonCollection.ConnectionString.Equals(string.Empty))
            {
                using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
                {
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("r_release_organization_hard_lock_procedure", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@organization_id", SqlDbType.NVarChar).Value = oCOrganization.OrganizationId;
                        cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = oCOrganization.CreatedBy;

                        cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                        cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                        cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();

                        if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                        {
                            oCStatus.Success = true;
                            oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                        }
                        else
                        {
                            oCStatus.Success = false;
                            oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                            //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                        }
                    }
                    catch (Exception ex)
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = ex.Message;
                    }
                }
            }
            else
            {
                oCStatus.Success = false;
                oCStatus.StatusDetails = CAppErrorsConstants.ConStringNotFound;
            }

            return oCStatus;
        }

        #endregion

    }
}